<?php
/**
 * Created by PhpStorm.
 * User: wangx08
 * Date: 2015-03-28
 * Time: 17:19
 */
namespace common\repositories\config;


use common\entities\config\ConfigSettingsEntity;
use common\repositories\BaseRepository;

class ConfigSettingRepository extends BaseRepository {

    /**
     * @param $key
     * @return ConfigSettingsEntity|null
     */
    public function getByKey($key){
        $config = ConfigSettingsEntity::findOne(array(
            "KeyName"=>$key
        ));
        return $config;
    }

    public function getValueByKey($key){
        $config = ConfigSettingsEntity::findOne(array(
            "KeyName"=>$key
        ));
        
        if ($config)
        {
        	return $config['Value'];
        }
        
        return '';
    }

    public function getByKeys(array $keys){
        $data = ConfigSettingsEntity::find()->where(["KeyName"=>$keys])->all();
        $result = [];
        foreach ($data as $entity) {
            $result[strtolower($entity->KeyName)] = $entity->Value;
        }
        return $result;
    }

    public function getValuesByKeys(array $keys){
        $data = ConfigSettingsEntity::find()->where(["KeyName"=>$keys])->all();
        $result = [];
        foreach ($data as $entity) {
            $result[$entity->KeyName] = $entity->Value;
        }
        return $result;
    }
    
    /**
     * 获取移动销售微网站地址
     * @return mixed
     */
    public function getYdxsMicrositeUrl()
    {
        return $this->getValueByKey('SalesSiteUrl');
    }
}